package com.example.shijianfenfa;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {
    String TAG = "MainActivity";
    @BindView(R.id.mv)
    MyView mMv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();
    }

    @SuppressLint("ClickableViewAccessibility")
    private void initView() {
        //触摸事件的监听
//        mMv.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                //onTOuchEvent先走还是这个onTouch先走 ??
//                //onTouch方法先走
//                Log.d(TAG, "onTouch: ");
//                return false;
//            }
//        });
        mMv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //onTouchEvent先走,onclick后走
                //因为onclick是在onTouchEvent内部调用的
                Log.d(TAG, "onClick: ");
            }
        });
    }

    /**
     * 分发事件的方法
     * getWindow().superDispatchTouchEvent(ev)
     * getWindow = PhoneWindow
     * mDecor.superDispatchTouchEvent(event);
     * DecorView mDecor; 是一个帧布局
     *
     * @param ev
     * @return
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
 /*       public static final int ACTION_DOWN             = 0;
        public static final int ACTION_UP               = 1;
        public static final int ACTION_MOVE             = 2;
        public static final int ACTION_CANCEL           = 3;*/
        Log.d(TAG, "dispatchTouchEvent: " + ev.getAction());
        //super.dispatchTouchEvent(ev) 事件分发
        //true:事件被消费了
        //false:无处理
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i(TAG, "onTouchEvent: "+event.getAction());
        return super.onTouchEvent(event);
    }

}